﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTOFrameworks;
using FAQFrameworks;
using FooFun.DataElements.Dtos;

namespace FooFun.Web.Controls
{
    public class RemarkFormControl : DataElementControl
    {
        public override IDataElement DataElement
        {
            get
            {
                return base.DataElement;
            }
            set
            {
                IDataElement de = value;

                if (FAQContext.Current.User.AccountId == Guid.Empty)
                {
                    base.DataElement
                        = new EmptyDataElement
                            ("匿名用户无法评论");

                    return;
                }

                if (de != null
                    && !de.IsEmpty)
                {
                    IDataElement eventDataElement = de["@EventId"];

                    if (eventDataElement.IsEmpty)
                    {
                        base.DataElement
                            = new EmptyDataElement();

                        return;
                    }

                    EventManager eventManager = new EventManager();

                    if (!eventManager.GetElement(eventDataElement)
                        ["AccountId"].Equals(
                    FAQContext.Current.User.AccountId))
                    {
                        base.DataElement
                            = new EmptyDataElement();

                        return;
                    }
                    if (de["@Status"].Equals("Sealed"))
                    {
                        base.DataElement
                           = new EmptyDataElement();

                        return;
                    }
                }
                base.DataElement = de;

            }
        }
    }
}
